//
//  Settings.cpp
//  WiFiMACSim
//
//  Created by Christopher Kemsley on 4/1/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#include "Settings.hpp"

extern "C" {
#include <stdlib.h>
#include <time.h>
#include <math.h>
}



SimNamespaceBegin



Settings&	Settings::shared ()
	{
	static Settings s ;
	return s ;
	}


Settings :: Settings ()
:	dataPacketDuration		( 100 )		// 1500*8/6E6/20E-6
,	controlPacketDuration	( 2 )		// 30*8/6E6/20E-6
,	SIFSDuration			( 1 )		// 20us
,	DIFSDuration			( 2 )		// 40us
,	CW0						( 8 )		// As specified
,	CWMax					( 1024 )	// As specified
,	simulationDuration		( 500000 )	// 10/20E-6
	{
	srand ( time(0) ) ;
	}
Settings :: ~Settings ()
	{
	
	}

UInteger	Settings :: poissonSlotCount	( UInteger lambdaScalar )
	{
	double	lnScalar	=	-50000. / ((double)(lambda*lambdaScalar)) ;
	double	lnValue		=	( (double) (rand() % 100000000) ) / 100000000. ;
	lnValue				=	log ( 1 - lnValue ) ;
	UInteger	ret		=	lnValue * lnScalar ;
	return	ret ;
	}
UInteger	Settings :: uniformBackoff		()
	{
	return  1  +  (rand()%(CW0-1)) ;
	}



SimNamespaceEnd
